package own.stu.jobgib.playown.protobuf;

import com.google.protobuf.InvalidProtocolBufferException;
import own.stu.jobgib.playown.protobuf.model.AddressBookRemote;

public class Demo {
    public static void main(String[] args) throws InvalidProtocolBufferException {
        AddressBookRemote.Person person1 = AddressBookRemote.Person.newBuilder()
                .setId(1)
                .setName("xxx")
                .setEmail("sdfghj")
                .build();

        AddressBookRemote.Person person2 = AddressBookRemote.Person.newBuilder()
                .setId(2)
                .setName("yyyy")
                .setEmail("fwget")
                .build();

        System.out.println(person1);

        AddressBookRemote.AddressBook addressBook = AddressBookRemote.AddressBook.newBuilder()
                .addPeople(person1)
                .addPeople(person2)
                .build();
        System.out.println(addressBook.getPeopleList());


        System.out.println(" ======================== ");

        byte[] bytes = person1.toByteArray();
        AddressBookRemote.Person person3 = AddressBookRemote.Person.parseFrom(bytes);
        System.out.println(person3);

    }
}
